<%--
  Created by IntelliJ IDEA.
  User: a'su's
  Date: 2020/9/21
  Time: 23:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>个人资料(房东)</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../../../taofang/plugins/bootstrap-3.3.7-dist/css/bootstrap.css">
    <link rel="stylesheet" href="../../../taofang/css/TenantCentre.css">
    <link rel="stylesheet" href="../../../taofang/css/home.css">
</head>
<body>
<script src="../../../taofang/plugins/jquery-3.4.1.js"></script>
<script src="../../../taofang/plugins/bootstrap-3.3.7-dist/js/bootstrap.js"></script>

<%@include file="top.jsp"%>

<div class="col-md-9 zy5" style="height: 540px">
    <p class="zy51">个人资料</p>
    <p class="zy52"></p>
    <div class="zy53">
        <img src="../../../taofang/img/zy53.png">基本账号资料
    </div><hr>
    <div class="zy54">
        头像:
        <img class="img-circle zy56" src="../../../taofang/img/h2.png">
        <button class="btn btn-primary btn-lg zy55" data-toggle="modal" data-target="#myModal1">修改</button>
        <div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel1">更改头像</h4>
                    </div>
                    &nbsp&nbsp&nbsp
                    <input class="zy56" type="text" placeholder="请输入更改的手机号">
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary">提交更改</button>
                    </div>
                </div>
            </div>
        </div>
    </div><hr>
    <div class="zy54">
        账号:
        ${register.account}
    </div>
    <div class="zy54">
        密码:
        <span id="pwdspan" class="zy56" style="display: none">${register.password}</span>
        <span class="zy56">*****</span>
        <button class="btn btn-primary btn-lg zy55" data-toggle="modal" data-target="#myModal2">修改</button>
        <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel2">密码更改</h4>
                    </div>
                    &nbsp;修改密码:
                    <input id="pwd" class="zy56" type="password" placeholder="请输入更改的密码&nbsp;(6-8位,字母或者数字)" onblur="pwd1()" onfocus="pwd11()">
                    <span style="color: red;display: none" id="pwdspan1">密码格式不对</span>
                    <span id="pwdspan2" style="color: red;display: none">密码与原密码一样</span>
                    <br>
                    &nbsp;确认密码:
                    <input id="pwd2" class="zy56" type="password" placeholder="请再次输入更改的密码" onblur="pwd4()" onfocus="pwd44()">
                    <span style="color: red;display: none" id="pwdspan4">密码与上面密码不一致</span>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" onclick="changepwd()" class="btn btn-primary">提交更改</button>
                    </div>
                </div>
            </div>
        </div>
    </div><hr>
    <div class="zy54">
        手机:
        <span id="phonespan" class="zy56">${landlord.phone}</span>
        <button class="btn btn-primary btn-lg zy55" data-toggle="modal" data-target="#myModal3">修改</button>
        <div class="modal fade" id="myModal3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel3">手机号更改</h4>
                    </div>
                    &nbsp;&nbsp;&nbsp
                    <input class="zy56" id="phone" type="text" placeholder="请输入更改的手机号">
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" onclick="changephone()" data-dismiss="modal" class="btn btn-primary">提交更改</button>
                    </div>
                </div>
            </div>
        </div>
    </div><hr>
    <div class="zy54">
        姓名:
        <span id="namespan" class="zy56">${landlord.name}</span>
        <button class="btn btn-primary btn-lg zy55" data-toggle="modal" data-target="#myModal4">修改</button>
        <div class="modal fade" id="myModal4" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel4">姓名添加修改</h4>
                    </div>
                    &nbsp&nbsp&nbsp
                    <input id="nameinput" class="zy56" type="text" placeholder="请输入姓名(10个字符以内)">
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" onclick="changename()" data-dismiss="modal" class="btn btn-primary">提交</button>
                    </div>
                </div>
            </div>
        </div>
    </div><hr>
    <div class="zy54">
        <span style="float: left">性别:</span>
        <div style="padding-top: 2%">
            <select id='gender' onchange="changegender()" class="form-control zy577">
                <option <c:if test="${landlord.gender==true}">selected</c:if>>男</option>
                <option <c:if test="${landlord.gender==false}">selected</c:if>>女</option>
            </select>
        </div>
    </div>
</div>

<input type="hidden" id="registerId" value="${register.id}">


<%@include file="bottom.jsp"%>







<script>


    function pwd1() {
        let pwd = $("#pwd").val();
        let pwdspan = $("#pwdspan").text();
        let pwdspan2 = document.getElementById("pwdspan2")
        let pwdspan1 = document.getElementById("pwdspan1")
        if (pwd==pwdspan){
            pwdspan2.style.display="inline"
        }
        if (!(/^[a-zA-Z0-9]{6,8}$/).test(pwd) && pwd!=""){
            pwdspan1.style.display="inline"
        }


    }


    function pwd11() {
        let pwdspan2 = document.getElementById("pwdspan2")
        let pwdspan1 = document.getElementById("pwdspan1")
        pwdspan2.style.display="none"
        pwdspan1.style.display="none"
    }


    function pwd4() {
        let pwd = $("#pwd").val();
        let pwd4 = $("#pwd2").val();
        let pwdspan4 = document.getElementById("pwdspan4")
        if (pwd!=pwd4 && pwd4!=""){
            pwdspan4.style.display="inline"
        }
        if (pwd4==""){
            pwd4.style.display="none"
        }

    }


    function pwd44() {
        let pwdspan4 = document.getElementById("pwdspan4")
        pwdspan4.style.display="none"
    }

    function changepwd() {
        let pwd = $("#pwd").val();
        let pwd4 = $("#pwd2").val();
        let pwdspan2 = document.getElementById("pwdspan2")
        let pwdspan1 = document.getElementById("pwdspan1")
        // let pwdspan3 = document.getElementById("pwdspan3")
        let pwdspan4 = document.getElementById("pwdspan4")
        if(  pwdspan2.style.display=="none" &&
            pwdspan1.style.display=="none" && pwdspan4.style.display=="none" && pwd!="" && pwd4!=""){
            let registerId = $("#registerId").val();
            let datas = {"id": registerId, "password": pwd}
            $.post('/taofang/Tenant/changepwd.action', datas, function (data) {
                if (data.code == 200) {
                    alert("修改成功")
                    window.location="/taofang/login/check.action"
                }else{
                    alert("修改失败")
                }
            })
        }else{
            alert("请输入正确的修改密码")
        }
    }




    function changephone() {
        let phone = $("#phone").val()
        let span = $("#phonespan").text();
        if (phone!=""){
            if(phone==span){
                alert("修改的手机号不能和原来手机号一样")
            }else {

                if ((/^1(3[0-9]|5[0-9]|8[0-9])[0-9]{8}$/).test(phone)) {
                    let landlordId = $("#landlordId").val();
                    let datas = {"id": landlordId, "phone": phone}
                    $.post('/taofang/Landlord/changephone.action', datas, function (data) {
                        if (data.code == 200) {
                            alert("修改成功")
                            let phonespan = document.getElementById("phonespan").innerText = data.data.phone;
                        }
                    })
                } else {
                    alert("请输入正确的手机号")
                }


            }
        }else{
            alert("修改不能为空")
        }
    }




    function changename() {
        let name = $("#nameinput").val();
        let names=$("#namespan").text();
        if (name!=""){
            if (name==names) {
                alert("修改的姓名不能和原来姓名一样")
            }else{
                if (name.length<11) {
                    let landlordId = $("#landlordId").val();
                    let datas = {"id": landlordId, "name": name}
                    $.post('/taofang/Landlord/changename.action', datas, function (data) {
                        if (data.code == 200) {
                            alert("修改成功")
                            let namespan = document.getElementById("namespan").innerText = data.data.name;
                        }
                    })

                }else{
                    alert("姓名不能超过10字符")
                }
            }
        }else{
            alert("修改不能为空")
        }
    }



    function changegender() {
        let genval = $("#gender").val();
        let vals;
        if ("男"==genval){
            vals = "true";
        }else{
            vals="false";
        }

        let landlordId = $("#landlordId").val();
        let datas={"id":landlordId,"gender":vals}
        $.post('/taofang/Landlord/changegender.action',datas,function (data){
            if (data.code==200){
                alert("修改成功")
            }
        })
    }
</script>







</body>
</html>
